<?php
class adController extends accessController{
    public static function _right(){
        return array(
            array('广告管理',1),
            array('广告添加','add,add_'),
            array('广告列表','mylist'),
            array('广告编辑','mod,mod_'),
            array('广告删除','del'),
            array('静态生成','html,html_'),
            array('批量操作','bit_op'),
        );
    }
	public function s(){
		return array('ad');
	}
	public function add(){
		$mysort=time();
		include($this->viewer_dir.'ad/add.php');
	}
	public function add_(){
    	if($_POST){
			$r=$this->s_0->add_($_POST);
			autoalert($r[0],$r[1]);
			back();
        }
    }
	public function mylist(){
	    
        $status_data=array('-1'=>'--请选择--','0'=>'隐藏','1'=>'显示');
        
		$condition=array();
		$extra='';
        $extra_data=array();
        
		$id=intval($_GET['id']);//
		if($id){
			$condition['id']=$id;
			$extra.=" and `id`=:id";
			$extra_data['id']=$id;
		}
		
		$title=trim($_GET['title']);//
		if($title){
			$condition['title']=$title;
			$extra.=" and `title` like :title";
			$extra_data['title']="%{$title}%";
		}

        isset($_GET['status']) or $_GET['status']=-1;
		$status=intval($_GET['status']);//
		if($status>-1){
			$condition['status']=$status;
			$extra.=" and `status`=:status";
			$extra_data['status']=$status;
		}
		
	    $return=$this->s_0->li($condition,$extra,$extra_data);
		include($this->viewer_dir.'ad/mylist.php');
	}
	public function mod(){
        $id=intval($_GET['id']);
        if($id>0){
            $data=$this->s_0->mod($id);
            if($data){
                include($this->viewer_dir.'ad/mod.php');
            }
        }
    }
    public function mod_(){
		$id=intval($_GET['id']);
        if($_POST and $id>0){
            $r=$this->s_0->mod_($_POST,$id);
            autoalert($r[0],$r[1]);
            back();
        }
    }
	public function del(){
		$id=intval($_GET['id']);
        if($id>0){
            $r=$this->s_0->del($id);
            autoalert($r[0],$r[1]);
            back();
        }
	}
    //批量操作 文章列表页调用
	public function bit_op(){
		if(empty($_POST)) exit;
		$k=$_GET['k'];
		$items=$_POST['items'];
		if(empty($items)) exit;
		switch($k){
			case 'make_html'://已做
			$this->s_0->make_html($items);
			break;
            case 'update_status'://已做
			$this->s_0->update_status($items,$_POST['status']);
			break;
			default:
			exit('k error!');
			break;
		}
		alert('操作成功！');
		back();
	}
    public function html(){
		list($fid,$tid)=$this->s_0->return_min_max();
		$fid=intval($fid);
		$tid=intval($tid);
		$num=100;
		include($this->viewer_dir.'ad/html.php');
	}
	public function html_(){
		$k=trim($_GET['k']);
		switch($k){
			case 'show':
			$this->s_0->html_show();
			break;
			default:
			exit('k error!');
			break;
		}
	}
    
//
}